package de.velvettear.squirrel.util;

import java.util.UUID;

import android.util.Log;
import de.velvettear.squirrel.kernel.Settings;
import de.velvettear.squirrel.kernel.Statics;

public class SettingsHelper {

	public static void createSettings() {
		Log.i("createSettings()", "BEGIN");
		
		for (String name : Statics.SETTINGS) {
			Settings setting = new Settings();
			setting.getSettingsByName(name);
			if (setting.m_sName.length() == 0) {
				setting.m_sName = name;
				setting.store();
			}
		}	
			
		Log.i("createSettings()", "END");
	}
	
	public static void setDefaultSettings() {
		Log.i("setDefaultSettings()", "BEGIN");
		
		Settings settings = new Settings();
		settings.getSettingsByName(Statics.SETTINGS_CHAT_ACTIVATED);
		if (settings.isValid()) {
			if (settings.m_sValue.trim().length() == 0) {
				settings.m_sValue = Statics.STATUS_INACTIVE;
				settings.store();
			}			
		}
				
		settings = new Settings();
		settings.getSettingsByName(Statics.SETTINGS_CHAT_HOST);
		if (settings.isValid()) {
			if (settings.m_sValue.trim().length() == 0) {
				settings.m_sValue = "velvettear.no-ip.org";
				settings.store();
			}			
		}
		
		settings = new Settings();
		settings.getSettingsByName(Statics.SETTINGS_CHAT_PORT);
		if (settings.isValid()) {
			if (settings.m_sValue.trim().length() == 0) {
				settings.m_sValue = "5222";
				settings.store();
			}			
		}
		
		settings = new Settings();
		settings.getSettingsByName(Statics.SETTINGS_CHAT_SERVICE);
		if (settings.isValid()) {
			if (settings.m_sValue.trim().length() == 0) {
				settings.m_sValue = "raspberry";
				settings.store();
			}			
		}
		
		settings = new Settings();
		settings.getSettingsByName(Statics.SETTINGS_CHAT_MODE);
		if (settings.isValid()) {
			if (settings.m_sValue.trim().length() == 0) {
				settings.m_sValue = Statics.CHAT_MODE_ONLINE;
				settings.store();
			}			
		}
		
		settings = new Settings();
		settings.getSettingsByName(Statics.SETTINGS_CHAT_STATUS);
		if (settings.isValid()) {
			if (settings.m_sValue.trim().length() == 0) {
				settings.m_sValue = "";
				settings.store();
			}			
		}		
		
		settings = new Settings();
		settings.getSettingsByName(Statics.SETTINGS_CHAT_USERNAME);
		if (settings.isValid()) {
			if (settings.m_sValue.trim().length() == 0) {
				settings.m_sValue = IdentificationHelper.getSerialNumber();
				settings.store();
			}
		}
		
		settings = new Settings();
		settings.getSettingsByName(Statics.SETTINGS_CHAT_ALIAS);
		if (settings.isValid()) {
			if (settings.m_sValue.trim().length() == 0) {
				settings.m_sValue = "Anonymous";
				settings.store();
			}
		}
		
		settings = new Settings();
		settings.getSettingsByName(Statics.SETTINGS_CHAT_PASSWORD);
		if (settings.isValid()) {
			if (settings.m_sValue.trim().length() == 0) {
				settings.m_sValue = EncryptionHelper.encrypt(IdentificationHelper.getSerialNumber());
				settings.store();
			}
		}
		
		Log.i("setDefaultSettings()", "END");
	}
	
}
